Real 3-D

level: advanced

© 2005, Stefan Hesseling

author contact:

sjmhesseling@hotmail.com


Home

ActiveX DLLs 2

API Trackbar/Slider

OOP

Stylebits - Textboxes

Using a ListBox

Real 3-D

Context Sensitive Help

Program Design

Texteditors

Tip Corner - Nomainwin

API Corner - MainWin

Sprite Byte: Scoreboard

Eddie

Newsletter help

Index

3D Glasses

Real3D is a program to view objects with an experience that is very close to reality. To get the full experience you need a pair of glasses with one red glass and one green glass. If you don't have one, the program lets you produce a stencil to D.I.Y.

Theory

To understand the program it is necessary to understand how our eyes and brain work together to give us in-depth sight. Because there is a distance between our two eyes our left eye is seeing a slightly different picture than our right eye. The closer an object is to our eyes the greater the difference is. In actuality, your nose is positioned right in the picture your left eye sees, and it is positioned left in the picture your right eye sees. Our brain mixes both pictures to one experience. The more an object's postion differs in both pictures the closer it is to our eyes.

To create real 3d we have to fool our brain and give our left eye a (slightly)different picture than our right eye. The problem is that we only have one computer screen. But when we use a red-green pair of glasses we can let the left eye see only green pixels in our screen and let the right eye see only red pixels. Fortunately our brain "looks" at position only. The color difference of an object is hardly a problem for our brain. So every point of an object will be projected on our computer screen twice: one green pixel and one red pixel. If there is a great distance between these two pixels our brain thinks this point is close to our eyes and (vice versa). If there is a small distance between both pixels the point must be far away. This gives a real 3D experience!

The Program

At first we select an object: a cube, a pyramid, a prism, a cylinder, a diamond, a sphere or a star. For some of these objects we can set the number of edgepoints. The program fills an array P, representing edgepoints of the object. Then it fills a Lines array corresponding to the edges of this object by storing the indices of the startpoint and endpoint of an edge. These points P wil be rotated in X, Y and/or Z direction and stored in points Q.

Then the program calculates a green X screen coordinate and a green Y screen coordinate and stores these in the Q array too. Then again, it calculates a red X and a red Y screen coordinate and stores it in the Q array too. This calculation is a matter of simple vector calculus, done in the sub "calculateScreenPoints." After a green-red shift and an origin repositioning, the program can now display green and red lines on the computer screen.

To give a feeling of motion, new Q points will be calculated in relation with any new rotation angle. Then the old lines will be deleted and the new lines wil be drawn.

  TOP VIEW
 
                  -Z-axix
                   |
                   |
                   |                       O = Origin (but also the middle of the Object)
                  O|
 ------------------------------------- X-axis
                   |
                   |
                   | OSdz                  OSdz = Origin<->Screen distance
                   |
                   |
              -----------  Screen
                   |
                   | SEdz                  SEdz = Screen<->Eyes distance
                   |
        Eye left o---o Eye right

Adjustments

Improvements

I tried to reduce the flickering by using the memory drawing as described by Alyce Watson in NewsLetter 101. Unfortunately this results in a hesitation now and then. So, I disabled it. Perhaps someone can improve the still existing (dead) code.

Feel free to make some more objects: the prism and pyramid can easily have more planes by increasing the "nEdges". When you make totally new objects be aware that your point lies in the sphere around (0,0,0) with a radius of 300 (i.e. sbminimal(4)). Forgetting this rule will result in possibly moving your object through the screen, giving very weird effects such as no glass smithering.

Have fun with it!

The 3D Code

The file real3d.bas is included in the zipped archive of this newsletter.


Home

ActiveX DLLs 2

API Trackbar/Slider

OOP

Stylebits - Textboxes

Using a ListBox

Real 3-D

Context Sensitive Help

Program Design

Texteditors

Tip Corner - Nomainwin

API Corner - MainWin

Sprite Byte: Scoreboard

Eddie

Newsletter help

Index